package gui;

import houseHold.House;

import java.awt.Dimension;
import java.awt.Point;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.border.BevelBorder;

import RoomPanel.RoomPanelRemover;

public class RoomPopupMenu {

	private int id;
	private JMenuItem ObjectInfo;
	private JMenuItem RemoveRoom;
	private JMenuItem RoomInfo;

	private JPopupMenu RoomPopUp;

	public int getId() {
		return id;
	}

	private JMenuItem getObjectInfo() {
		if (ObjectInfo == null) {
			ObjectInfo = new JMenuItem();
			ObjectInfo.setText("Object Information");
			ObjectInfo.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if (House.getInstance().getRoomByID(id) != null) {
						HouseEditor.getInstance().setEnabled(false);
						ObjectInfoDialog OID = new ObjectInfoDialog(HouseEditor
								.getInstance());
						System.out.println(House.getInstance().getRoomByID(id));
						OID.initialize(House.getInstance().getRoomByID(id));
						Point loc = HouseEditor.getInstance().getLocation();
						loc.translate(50, 50);
						OID.setLocation(loc);
						OID.setSize(new Dimension(800, 300));
						OID.setVisible(true);
					} else
						System.out.println("room error");
				}
			});

		}
		return ObjectInfo;
	}

	/**
	 * This method initializes RemoveRoom
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getRemoveRoom() {
		if (RemoveRoom == null) {
			RemoveRoom = new JMenuItem();
			RemoveRoom.setText("Remove Room");
			RemoveRoom.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					RoomPanelRemover.remove(id);
					House.getInstance().removeRoom(id);
				}
			});
		}
		return RemoveRoom;
	}

	/**
	 * This method initializes AddObject
	 * 
	 * @return javax.swing.JMenuItem
	 */

	/**
	 * This method initializes RoomInfo
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getRoomInfo() {
		if (RoomInfo == null) {
			RoomInfo = new JMenuItem();
			RoomInfo.setText("Room Information");
			RoomInfo.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if (House.getInstance().getRoomByID(id) != null) {
						HouseEditor.getInstance().setEnabled(false);
						RoomInformationDialog RID = new RoomInformationDialog(
								HouseEditor.getInstance());
						RID.initialize(House.getInstance().getRoomByID(id));
						Point loc = HouseEditor.getInstance().getLocation();
						loc.translate(50, 50);
						RID.setLocation(loc);
						RID.setSize(new Dimension(700, 310));
						RID.setVisible(true);
					} else
						System.out.println("room error");
				}
			});

		}
		return RoomInfo;
	}

	public JPopupMenu getRoomPopUp() {
		if (RoomPopUp == null) {
			RoomPopUp = new JPopupMenu();
			RoomPopUp.setSize(new Dimension(80, 120));
			RoomPopUp.add(getRoomInfo());
			RoomPopUp.add(getObjectInfo());
			RoomPopUp.addSeparator();
			RoomPopUp.setBorder(new BevelBorder(BevelBorder.RAISED));
			RoomPopUp.add(getRemoveRoom());
		}
		return RoomPopUp;
	}

	public void setId(int id) {
		this.id = id;
	}
}
